import time
import unittest
from HTMLTestRunner import HTMLTestRunner


# 构建测试套件
suite = unittest.TestSuite()
# 构建加载器
Loader = unittest.TestLoader()

suite.addTests(Loader.discover(r'C:\pythonfile\python\bysj\test_', 'test*.py'))

# 把测试结果保存在html文件中
filename = time.strftime("%Y-%m-%d-%H-%M-%S") + '测试报告' + r".html"
with open(filename, 'w+', encoding='utf-8') as f:
    # 执行测试
    runner = HTMLTestRunner(stream=f, verbosity=2, title='测试用例执行报告', description='叮当书城测试报告')
    runner.run(suite)


